package com.ruoyi.system.api.wrapper;

import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteSysDictDataService;
import com.ruoyi.system.api.domain.SysDictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 字典数据微服务包装服务，对微服务接口进行了封装，直接返回需要的数据。
 *
 * @author ruoyi
 * @date 2023-04-27
 */
@Component
public class RemoteSysDictDataWrapperService extends RemoteBaseWrapperService {

    @Autowired
    private RemoteSysDictDataService remoteSysDictDataService;

    /**
     * 查询字典数据
     *
     * @param dictCode 字典数据主键
     * @return 字典数据
     */
    public SysDictData selectSysDictDataByDictCode(Long dictCode) {
        R<SysDictData> result = remoteSysDictDataService.selectSysDictDataByDictCode(dictCode, SecurityConstants.INNER);
        return processResult(result);
    }

    /**
     * 查询字典数据列表
     *
     * @param sysDictData 字典数据
     * @return 字典数据集合
     */
    public List<SysDictData> selectSysDictDataList(SysDictData sysDictData) {
        R<List<SysDictData>> result = remoteSysDictDataService.selectSysDictDataList(sysDictData, SecurityConstants.INNER);
        return processResult(result);
    }

    /**
     * 新增字典数据
     *
     * @param sysDictData 字典数据
     * @return 结果
     */
    public Integer insertSysDictData(SysDictData sysDictData) {
        R<Integer> result = remoteSysDictDataService.insertSysDictData(sysDictData, SecurityConstants.INNER);
        return processResult(result);
    }

    /**
     * 修改字典数据
     *
     * @param sysDictData 字典数据
     * @return 结果
     */
    public Integer updateSysDictData(SysDictData sysDictData) {
        R<Integer> result = remoteSysDictDataService.updateSysDictData(sysDictData, SecurityConstants.INNER);
        return processResult(result);
    }

    /**
     * 批量删除字典数据
     *
     * @param dictCodes 需要删除的字典数据主键集合
     * @return 结果
     */
    public Integer deleteSysDictDataByDictCodes(Long[] dictCodes) {
        R<Integer> result = remoteSysDictDataService.deleteSysDictDataByDictCodes(dictCodes, SecurityConstants.INNER);
        return processResult(result);
    }
}
